package com.annhoa.infrastructure.util;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;

import java.io.InputStreamReader;

public class FileUtils {
    public static JSONObject getJSON(String path){
        JSONObject json = null;
        try {
            //路径
            ClassPathResource classPathResource = new ClassPathResource(path);
            //读取文件信息
            String str = IOUtils.toString(new InputStreamReader(classPathResource.getInputStream(),"UTF-8"));
            //转换为json对象
            json = JSONObject.parseObject(str);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }
}
